package git.soulbgm.service;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import org.springframework.stereotype.Service;

/**
 * @author SoulBGM
 * @version 1.0
 * @date 2020/8/14
 */
@Service
public class DemoService {

    @SentinelResource(value = "doSomeThing", blockHandler = "exceptionHandler")
    public void doSomeThing(String str) {
        System.out.println("doSomeThing echo " + str);
    }

    /**
     * 限流与阻塞处理
     */
    public void exceptionHandler(String str, BlockException ex) {
        System.out.println("blockHandler: " + str + " 异常: " + ex);
    }

    @SentinelResource(value = "doSomeThing2", fallback = "fallbackHandler")
    public void doSomeThing2(String str) {
        System.out.println("doSomeThing2 echo " + str);
        throw new RuntimeException("熔断降级");
    }

    /**
     * 熔断与降级处理
     */
    public void fallbackHandler(String str) {
        System.err.println("fallbackHandler: " + str);
    }

}
